FROM python:3.9-alpine

WORKDIR /app


# 导包时不生成.pyc文件
ENV PYTHONDONTWRITEBYTECODE 1
# 防止python缓存stdout和stderr
ENV PYTHONUNBUFFERED 1

RUN pip install --upgrade pip
COPY ./requirements.txt .

# default-libmysqlclient-dev - mysqlclient需要
# alpine包使用mariadb-dev,详情查看:
# https://nickjanetakis.com/blog/docker-tip-9-installing-popular-packages-on-alpine
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers mariadb-dev
RUN pip install -r requirements.txt -i https://pypi.douban.com/simple

COPY ./myproject .

COPY ./scripts /scripts

# 添加环境路径，为了执行下面的entrypoint.sh
ENV PATH="/scripts:${PATH}"

RUN chmod +x /scripts/*

# RUN mkdir -p /app/media
RUN mkdir -p /app/static

RUN adduser -D appuser
RUN chown -R appuser:appuser /app
RUN chmod -R 755 /app/static
RUN chmod -R 755 /app/media
USER appuser

CMD ["entrypoint.sh"]
